<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>norwegianwoodstyle.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-widgets-styles-example.html">Styles Example</a></td><td >norwegianwoodstyle.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">norwegianwoodstyle.cpp 示例文件</h1>
<span class="subtitle">widgets/styles/norwegianwoodstyle.cpp</span>
<!-- $$$widgets/styles/norwegianwoodstyle.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the examples of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &lt;QtWidgets&gt;</span>

  <span class="preprocessor">#include &quot;norwegianwoodstyle.h&quot;</span>

  NorwegianWoodStyle<span class="operator">::</span>NorwegianWoodStyle() :
      <span class="type"><a href="qproxystyle.html">QProxyStyle</a></span>(<span class="type"><a href="qstylefactory.html">QStyleFactory</a></span><span class="operator">::</span>create(<span class="string">&quot;windows&quot;</span>))
  {
  }

  <span class="type">void</span> NorwegianWoodStyle<span class="operator">::</span>polish(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span> <span class="operator">&amp;</span>palette)
  {
      <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> brown(<span class="number">212</span><span class="operator">,</span> <span class="number">140</span><span class="operator">,</span> <span class="number">95</span>);
      <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> beige(<span class="number">236</span><span class="operator">,</span> <span class="number">182</span><span class="operator">,</span> <span class="number">120</span>);
      <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> slightlyOpaqueBlack(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">63</span>);

      <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> backgroundImage(<span class="string">&quot;:/images/woodbackground.png&quot;</span>);
      <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> buttonImage(<span class="string">&quot;:/images/woodbutton.png&quot;</span>);
      <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> midImage <span class="operator">=</span> buttonImage;

      <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> painter;
      painter<span class="operator">.</span>begin(<span class="operator">&amp;</span>midImage);
      painter<span class="operator">.</span>setPen(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>NoPen);
      painter<span class="operator">.</span>fillRect(midImage<span class="operator">.</span>rect()<span class="operator">,</span> slightlyOpaqueBlack);
      painter<span class="operator">.</span>end();

      palette <span class="operator">=</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span>(brown);

      palette<span class="operator">.</span>setBrush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>BrightText<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>white);
      palette<span class="operator">.</span>setBrush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Base<span class="operator">,</span> beige);
      palette<span class="operator">.</span>setBrush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Highlight<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>darkGreen);
      setTexture(palette<span class="operator">,</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Button<span class="operator">,</span> buttonImage);
      setTexture(palette<span class="operator">,</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Mid<span class="operator">,</span> midImage);
      setTexture(palette<span class="operator">,</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Window<span class="operator">,</span> backgroundImage);

      <span class="type"><a href="../qtgui/qbrush.html">QBrush</a></span> brush <span class="operator">=</span> palette<span class="operator">.</span>background();
      brush<span class="operator">.</span>setColor(brush<span class="operator">.</span>color()<span class="operator">.</span>dark());

      palette<span class="operator">.</span>setBrush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Disabled<span class="operator">,</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>WindowText<span class="operator">,</span> brush);
      palette<span class="operator">.</span>setBrush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Disabled<span class="operator">,</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Text<span class="operator">,</span> brush);
      palette<span class="operator">.</span>setBrush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Disabled<span class="operator">,</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>ButtonText<span class="operator">,</span> brush);
      palette<span class="operator">.</span>setBrush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Disabled<span class="operator">,</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Base<span class="operator">,</span> brush);
      palette<span class="operator">.</span>setBrush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Disabled<span class="operator">,</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Button<span class="operator">,</span> brush);
      palette<span class="operator">.</span>setBrush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Disabled<span class="operator">,</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Mid<span class="operator">,</span> brush);
  }

  <span class="type">void</span> NorwegianWoodStyle<span class="operator">::</span>polish(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget)
  {
      <span class="keyword">if</span> (qobject_cast<span class="operator">&lt;</span><span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(widget)
              <span class="operator">|</span><span class="operator">|</span> qobject_cast<span class="operator">&lt;</span><span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(widget))
          widget<span class="operator">-</span><span class="operator">&gt;</span>setAttribute(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>WA_Hover<span class="operator">,</span> <span class="keyword">true</span>);
  }

  <span class="type">void</span> NorwegianWoodStyle<span class="operator">::</span>unpolish(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget)
  {
      <span class="keyword">if</span> (qobject_cast<span class="operator">&lt;</span><span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(widget)
              <span class="operator">|</span><span class="operator">|</span> qobject_cast<span class="operator">&lt;</span><span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(widget))
          widget<span class="operator">-</span><span class="operator">&gt;</span>setAttribute(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>WA_Hover<span class="operator">,</span> <span class="keyword">false</span>);
  }

  <span class="type">int</span> NorwegianWoodStyle<span class="operator">::</span>pixelMetric(PixelMetric metric<span class="operator">,</span>
                                      <span class="keyword">const</span> <span class="type"><a href="qstyleoption.html">QStyleOption</a></span> <span class="operator">*</span>option<span class="operator">,</span>
                                      <span class="keyword">const</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget) <span class="keyword">const</span>
  {
      <span class="keyword">switch</span> (metric) {
      <span class="keyword">case</span> PM_ComboBoxFrameWidth:
          <span class="keyword">return</span> <span class="number">8</span>;
      <span class="keyword">case</span> PM_ScrollBarExtent:
          <span class="keyword">return</span> <span class="type"><a href="qproxystyle.html">QProxyStyle</a></span><span class="operator">::</span>pixelMetric(metric<span class="operator">,</span> option<span class="operator">,</span> widget) <span class="operator">+</span> <span class="number">4</span>;
      <span class="keyword">default</span>:
          <span class="keyword">return</span> <span class="type"><a href="qproxystyle.html">QProxyStyle</a></span><span class="operator">::</span>pixelMetric(metric<span class="operator">,</span> option<span class="operator">,</span> widget);
      }
  }

  <span class="type">int</span> NorwegianWoodStyle<span class="operator">::</span>styleHint(StyleHint hint<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="qstyleoption.html">QStyleOption</a></span> <span class="operator">*</span>option<span class="operator">,</span>
                                    <span class="keyword">const</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget<span class="operator">,</span>
                                    <span class="type"><a href="qstylehintreturn.html">QStyleHintReturn</a></span> <span class="operator">*</span>returnData) <span class="keyword">const</span>
  {
      <span class="keyword">switch</span> (hint) {
      <span class="keyword">case</span> SH_DitherDisabledText:
          <span class="keyword">return</span> <span class="type">int</span>(<span class="keyword">false</span>);
      <span class="keyword">case</span> SH_EtchDisabledText:
          <span class="keyword">return</span> <span class="type">int</span>(<span class="keyword">true</span>);
      <span class="keyword">default</span>:
          <span class="keyword">return</span> <span class="type"><a href="qproxystyle.html">QProxyStyle</a></span><span class="operator">::</span>styleHint(hint<span class="operator">,</span> option<span class="operator">,</span> widget<span class="operator">,</span> returnData);
      }
  }

  <span class="type">void</span> NorwegianWoodStyle<span class="operator">::</span>drawPrimitive(PrimitiveElement element<span class="operator">,</span>
                                         <span class="keyword">const</span> <span class="type"><a href="qstyleoption.html">QStyleOption</a></span> <span class="operator">*</span>option<span class="operator">,</span>
                                         <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">*</span>painter<span class="operator">,</span>
                                         <span class="keyword">const</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget) <span class="keyword">const</span>
  {
      <span class="keyword">switch</span> (element) {
      <span class="keyword">case</span> PE_PanelButtonCommand:
          {
              <span class="type">int</span> delta <span class="operator">=</span> (option<span class="operator">-</span><span class="operator">&gt;</span>state <span class="operator">&amp;</span> State_MouseOver) <span class="operator">?</span> <span class="number">64</span> : <span class="number">0</span>;
              <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> slightlyOpaqueBlack(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">63</span>);
              <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> semiTransparentWhite(<span class="number">255</span><span class="operator">,</span> <span class="number">255</span><span class="operator">,</span> <span class="number">255</span><span class="operator">,</span> <span class="number">127</span> <span class="operator">+</span> delta);
              <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> semiTransparentBlack(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">127</span> <span class="operator">-</span> delta);

              <span class="type">int</span> x<span class="operator">,</span> y<span class="operator">,</span> width<span class="operator">,</span> height;
              option<span class="operator">-</span><span class="operator">&gt;</span>rect<span class="operator">.</span>getRect(<span class="operator">&amp;</span>x<span class="operator">,</span> <span class="operator">&amp;</span>y<span class="operator">,</span> <span class="operator">&amp;</span>width<span class="operator">,</span> <span class="operator">&amp;</span>height);

              <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> roundRect <span class="operator">=</span> roundRectPath(option<span class="operator">-</span><span class="operator">&gt;</span>rect);
              <span class="type">int</span> radius <span class="operator">=</span> <a href="../qtcore/qtglobal.html#qMin">qMin</a>(width<span class="operator">,</span> height) <span class="operator">/</span> <span class="number">2</span>;

              <span class="type"><a href="../qtgui/qbrush.html">QBrush</a></span> brush;
              bool darker;

              <span class="keyword">const</span> <span class="type"><a href="qstyleoptionbutton.html">QStyleOptionButton</a></span> <span class="operator">*</span>buttonOption <span class="operator">=</span>
                      qstyleoption_cast<span class="operator">&lt;</span><span class="keyword">const</span> <span class="type"><a href="qstyleoptionbutton.html">QStyleOptionButton</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(option);
              <span class="keyword">if</span> (buttonOption
                      <span class="operator">&amp;</span><span class="operator">&amp;</span> (buttonOption<span class="operator">-</span><span class="operator">&gt;</span>features <span class="operator">&amp;</span> <span class="type"><a href="qstyleoptionbutton.html">QStyleOptionButton</a></span><span class="operator">::</span>Flat)) {
                  brush <span class="operator">=</span> option<span class="operator">-</span><span class="operator">&gt;</span>palette<span class="operator">.</span>background();
                  darker <span class="operator">=</span> (option<span class="operator">-</span><span class="operator">&gt;</span>state <span class="operator">&amp;</span> (State_Sunken <span class="operator">|</span> State_On));
              } <span class="keyword">else</span> {
                  <span class="keyword">if</span> (option<span class="operator">-</span><span class="operator">&gt;</span>state <span class="operator">&amp;</span> (State_Sunken <span class="operator">|</span> State_On)) {
                      brush <span class="operator">=</span> option<span class="operator">-</span><span class="operator">&gt;</span>palette<span class="operator">.</span>mid();
                      darker <span class="operator">=</span> <span class="operator">!</span>(option<span class="operator">-</span><span class="operator">&gt;</span>state <span class="operator">&amp;</span> State_Sunken);
                  } <span class="keyword">else</span> {
                      brush <span class="operator">=</span> option<span class="operator">-</span><span class="operator">&gt;</span>palette<span class="operator">.</span>button();
                      darker <span class="operator">=</span> <span class="keyword">false</span>;
                  }
              }

              painter<span class="operator">-</span><span class="operator">&gt;</span>save();
              painter<span class="operator">-</span><span class="operator">&gt;</span>setRenderHint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing<span class="operator">,</span> <span class="keyword">true</span>);
              painter<span class="operator">-</span><span class="operator">&gt;</span>fillPath(roundRect<span class="operator">,</span> brush);
              <span class="keyword">if</span> (darker)
                  painter<span class="operator">-</span><span class="operator">&gt;</span>fillPath(roundRect<span class="operator">,</span> slightlyOpaqueBlack);

              <span class="type">int</span> penWidth;
              <span class="keyword">if</span> (radius <span class="operator">&lt;</span> <span class="number">10</span>)
                  penWidth <span class="operator">=</span> <span class="number">3</span>;
              <span class="keyword">else</span> <span class="keyword">if</span> (radius <span class="operator">&lt;</span> <span class="number">20</span>)
                  penWidth <span class="operator">=</span> <span class="number">5</span>;
              <span class="keyword">else</span>
                  penWidth <span class="operator">=</span> <span class="number">7</span>;

              <span class="type"><a href="../qtgui/qpen.html">QPen</a></span> topPen(semiTransparentWhite<span class="operator">,</span> penWidth);
              <span class="type"><a href="../qtgui/qpen.html">QPen</a></span> bottomPen(semiTransparentBlack<span class="operator">,</span> penWidth);

              <span class="keyword">if</span> (option<span class="operator">-</span><span class="operator">&gt;</span>state <span class="operator">&amp;</span> (State_Sunken <span class="operator">|</span> State_On))
                  <a href="../qtcore/qtalgorithms-obsolete.html#qSwap-1">qSwap</a>(topPen<span class="operator">,</span> bottomPen);

              <span class="type">int</span> x1 <span class="operator">=</span> x;
              <span class="type">int</span> x2 <span class="operator">=</span> x <span class="operator">+</span> radius;
              <span class="type">int</span> x3 <span class="operator">=</span> x <span class="operator">+</span> width <span class="operator">-</span> radius;
              <span class="type">int</span> x4 <span class="operator">=</span> x <span class="operator">+</span> width;

              <span class="keyword">if</span> (option<span class="operator">-</span><span class="operator">&gt;</span>direction <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>RightToLeft) {
                  <a href="../qtcore/qtalgorithms-obsolete.html#qSwap-1">qSwap</a>(x1<span class="operator">,</span> x4);
                  <a href="../qtcore/qtalgorithms-obsolete.html#qSwap-1">qSwap</a>(x2<span class="operator">,</span> x3);
              }

              <span class="type"><a href="../qtgui/qpolygon.html">QPolygon</a></span> topHalf;
              topHalf <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(x1<span class="operator">,</span> y)
                      <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(x4<span class="operator">,</span> y)
                      <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(x3<span class="operator">,</span> y <span class="operator">+</span> radius)
                      <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(x2<span class="operator">,</span> y <span class="operator">+</span> height <span class="operator">-</span> radius)
                      <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(x1<span class="operator">,</span> y <span class="operator">+</span> height);

              painter<span class="operator">-</span><span class="operator">&gt;</span>setClipPath(roundRect);
              painter<span class="operator">-</span><span class="operator">&gt;</span>setClipRegion(topHalf<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>IntersectClip);
              painter<span class="operator">-</span><span class="operator">&gt;</span>setPen(topPen);
              painter<span class="operator">-</span><span class="operator">&gt;</span>drawPath(roundRect);

              <span class="type"><a href="../qtgui/qpolygon.html">QPolygon</a></span> bottomHalf <span class="operator">=</span> topHalf;
              bottomHalf<span class="operator">[</span><span class="number">0</span><span class="operator">]</span> <span class="operator">=</span> <span class="type"><a href="../qtcore/qpoint.html">QPoint</a></span>(x4<span class="operator">,</span> y <span class="operator">+</span> height);

              painter<span class="operator">-</span><span class="operator">&gt;</span>setClipPath(roundRect);
              painter<span class="operator">-</span><span class="operator">&gt;</span>setClipRegion(bottomHalf<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>IntersectClip);
              painter<span class="operator">-</span><span class="operator">&gt;</span>setPen(bottomPen);
              painter<span class="operator">-</span><span class="operator">&gt;</span>drawPath(roundRect);

              painter<span class="operator">-</span><span class="operator">&gt;</span>setPen(option<span class="operator">-</span><span class="operator">&gt;</span>palette<span class="operator">.</span>foreground()<span class="operator">.</span>color());
              painter<span class="operator">-</span><span class="operator">&gt;</span>setClipping(<span class="keyword">false</span>);
              painter<span class="operator">-</span><span class="operator">&gt;</span>drawPath(roundRect);

              painter<span class="operator">-</span><span class="operator">&gt;</span>restore();
          }
          <span class="keyword">break</span>;
      <span class="keyword">default</span>:
          <span class="type"><a href="qproxystyle.html">QProxyStyle</a></span><span class="operator">::</span>drawPrimitive(element<span class="operator">,</span> option<span class="operator">,</span> painter<span class="operator">,</span> widget);
      }
  }

  <span class="type">void</span> NorwegianWoodStyle<span class="operator">::</span>drawControl(ControlElement element<span class="operator">,</span>
                                       <span class="keyword">const</span> <span class="type"><a href="qstyleoption.html">QStyleOption</a></span> <span class="operator">*</span>option<span class="operator">,</span>
                                       <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">*</span>painter<span class="operator">,</span>
                                       <span class="keyword">const</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>widget) <span class="keyword">const</span>
  {
      <span class="keyword">switch</span> (element) {
      <span class="keyword">case</span> CE_PushButtonLabel:
          {
              <span class="type"><a href="qstyleoptionbutton.html">QStyleOptionButton</a></span> myButtonOption;
              <span class="keyword">const</span> <span class="type"><a href="qstyleoptionbutton.html">QStyleOptionButton</a></span> <span class="operator">*</span>buttonOption <span class="operator">=</span>
                      qstyleoption_cast<span class="operator">&lt;</span><span class="keyword">const</span> <span class="type"><a href="qstyleoptionbutton.html">QStyleOptionButton</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(option);
              <span class="keyword">if</span> (buttonOption) {
                  myButtonOption <span class="operator">=</span> <span class="operator">*</span>buttonOption;
                  <span class="keyword">if</span> (myButtonOption<span class="operator">.</span>palette<span class="operator">.</span>currentColorGroup()
                          <span class="operator">!</span><span class="operator">=</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>Disabled) {
                      <span class="keyword">if</span> (myButtonOption<span class="operator">.</span>state <span class="operator">&amp;</span> (State_Sunken <span class="operator">|</span> State_On)) {
                          myButtonOption<span class="operator">.</span>palette<span class="operator">.</span>setBrush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>ButtonText<span class="operator">,</span>
                                  myButtonOption<span class="operator">.</span>palette<span class="operator">.</span>brightText());
                      }
                  }
              }
              <span class="type"><a href="qproxystyle.html">QProxyStyle</a></span><span class="operator">::</span>drawControl(element<span class="operator">,</span> <span class="operator">&amp;</span>myButtonOption<span class="operator">,</span> painter<span class="operator">,</span> widget);
          }
          <span class="keyword">break</span>;
      <span class="keyword">default</span>:
          <span class="type"><a href="qproxystyle.html">QProxyStyle</a></span><span class="operator">::</span>drawControl(element<span class="operator">,</span> option<span class="operator">,</span> painter<span class="operator">,</span> widget);
      }
  }

  <span class="type">void</span> NorwegianWoodStyle<span class="operator">::</span>setTexture(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span> <span class="operator">&amp;</span>palette<span class="operator">,</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>ColorRole role<span class="operator">,</span>
                                      <span class="keyword">const</span> <span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span> <span class="operator">&amp;</span>pixmap)
  {
      <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> <span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>NColorGroups; <span class="operator">+</span><span class="operator">+</span>i) {
          <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> color <span class="operator">=</span> palette<span class="operator">.</span>brush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>ColorGroup(i)<span class="operator">,</span> role)<span class="operator">.</span>color();
          palette<span class="operator">.</span>setBrush(<span class="type"><a href="../qtgui/qpalette.html">QPalette</a></span><span class="operator">::</span>ColorGroup(i)<span class="operator">,</span> role<span class="operator">,</span> <span class="type"><a href="../qtgui/qbrush.html">QBrush</a></span>(color<span class="operator">,</span> pixmap));
      }
  }

  <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> NorwegianWoodStyle<span class="operator">::</span>roundRectPath(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qrect.html">QRect</a></span> <span class="operator">&amp;</span>rect)
  {
      <span class="type">int</span> radius <span class="operator">=</span> <a href="../qtcore/qtglobal.html#qMin">qMin</a>(rect<span class="operator">.</span>width()<span class="operator">,</span> rect<span class="operator">.</span>height()) <span class="operator">/</span> <span class="number">2</span>;
      <span class="type">int</span> diam <span class="operator">=</span> <span class="number">2</span> <span class="operator">*</span> radius;

      <span class="type">int</span> x1<span class="operator">,</span> y1<span class="operator">,</span> x2<span class="operator">,</span> y2;
      rect<span class="operator">.</span>getCoords(<span class="operator">&amp;</span>x1<span class="operator">,</span> <span class="operator">&amp;</span>y1<span class="operator">,</span> <span class="operator">&amp;</span>x2<span class="operator">,</span> <span class="operator">&amp;</span>y2);

      <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> path;
      path<span class="operator">.</span>moveTo(x2<span class="operator">,</span> y1 <span class="operator">+</span> radius);
      path<span class="operator">.</span>arcTo(<span class="type"><a href="../qtcore/qrect.html">QRect</a></span>(x2 <span class="operator">-</span> diam<span class="operator">,</span> y1<span class="operator">,</span> diam<span class="operator">,</span> diam)<span class="operator">,</span> <span class="number">0.0</span><span class="operator">,</span> <span class="operator">+</span><span class="number">90.0</span>);
      path<span class="operator">.</span>lineTo(x1 <span class="operator">+</span> radius<span class="operator">,</span> y1);
      path<span class="operator">.</span>arcTo(<span class="type"><a href="../qtcore/qrect.html">QRect</a></span>(x1<span class="operator">,</span> y1<span class="operator">,</span> diam<span class="operator">,</span> diam)<span class="operator">,</span> <span class="number">90.0</span><span class="operator">,</span> <span class="operator">+</span><span class="number">90.0</span>);
      path<span class="operator">.</span>lineTo(x1<span class="operator">,</span> y2 <span class="operator">-</span> radius);
      path<span class="operator">.</span>arcTo(<span class="type"><a href="../qtcore/qrect.html">QRect</a></span>(x1<span class="operator">,</span> y2 <span class="operator">-</span> diam<span class="operator">,</span> diam<span class="operator">,</span> diam)<span class="operator">,</span> <span class="number">180.0</span><span class="operator">,</span> <span class="operator">+</span><span class="number">90.0</span>);
      path<span class="operator">.</span>lineTo(x1 <span class="operator">+</span> radius<span class="operator">,</span> y2);
      path<span class="operator">.</span>arcTo(<span class="type"><a href="../qtcore/qrect.html">QRect</a></span>(x2 <span class="operator">-</span> diam<span class="operator">,</span> y2 <span class="operator">-</span> diam<span class="operator">,</span> diam<span class="operator">,</span> diam)<span class="operator">,</span> <span class="number">270.0</span><span class="operator">,</span> <span class="operator">+</span><span class="number">90.0</span>);
      path<span class="operator">.</span>closeSubpath();
      <span class="keyword">return</span> path;
  }

</pre>
</div>
<!-- @@@widgets/styles/norwegianwoodstyle.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
